package server

import (
	"context"
	"gluenet/modules/manager/server/adapter/iris-controller"
	"gluenet/modules/manager/server/adapter/metrics-cli"
	"gluenet/modules/manager/server/adapter/nats-cli"
	nats_controller "gluenet/modules/manager/server/adapter/nats-controller"
	"gluenet/modules/manager/server/adapter/repository"
	rest_cli "gluenet/modules/manager/server/adapter/rest-cli"
	"gluenet/modules/manager/server/adapter/syncer"
	"gluenet/modules/manager/server/infra/prepare"
)

func Run(ctx context.Context) {
	prepare.Register()

	// fisrt register repo
	if err := repository.Install(); err != nil {
		panic(err)
	}

	// then register cli
	if err := metrics_cli.Install(); err != nil {
		panic(err)
	}
	if err := nats_cli.Install(); err != nil {
		panic(err)
	}
	if err := rest_cli.Install(); err != nil {
		panic(err)
	}

	// next register controller
	if err := iris_controller.Install(); err != nil {
		return
	}
	if err := nats_controller.Install(); err != nil {
		return
	}

	// finally register syncer
	if err := syncer.Install(ctx); err != nil {
		panic(err)
	}
}
